/**
 * 系统配置信息
 */
import Foundation
import MJRefresh
import YYKit
import UIKit


////////////////////////////////////////////////////////////////////////////////
//MARK:  - 系统配置设置
////////////////////////////////////////////////////////////////////////////////
struct Setting {
    //包名
    static let K_APP_BUNDIE_IDENTIFIER = Bundle.main.infoDictionary?["CFBundleIdentifier"]
    
    //App 版本
    static let K_APP_VERSION = String.init(format:"%@.%@",Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! CVarArg,Bundle.main.infoDictionary!["CFBundleVersion"] as! CVarArg)
    
    //App name
    //Bundle.main.infoDictionary?["CFBundleDisplayName"]
    static let K_APP_NAME = NSLocalizedString("CFBundleDisplayName", tableName: "InfoPlist", bundle: Bundle.main, value: "", comment: "")
    
    //AppId
    static let K_APP_ID = "000000"
    
    
    ////////////////////////////////////////////////////////////////////////////////
    //MARK: - 常量设置
    ////////////////////////////////////////////////////////////////////////////////
    /** 导航栏高度 */
    static let K_APP_NAVIGATION_BAR_HEIGHT = CGFloat.init(UIDevice.current.isiPhoneX() ? 88 : 64)
    
    /** 导航背景色 */
    static let K_APP_NAVIGATION_BACKGROUND_COLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _bc = UIColor.init { (trainCollection:UITraitCollection) -> UIColor in
                if trainCollection.userInterfaceStyle == .dark {
                    return UIColor.systemBackground
                }
                return UIColor.white
            }
            return _bc
        }
        return UIColor.white
    }()
    
    /**
     * 视图背景色
     * https://www.jianshu.com/p/e6616e44cf60
     * iOS13-适配夜间模式/深色外观
     */
    static let K_APP_VIEWCONTROLLER_BACKGROUND_COLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _bc = UIColor.init { (trainCollection:UITraitCollection) -> UIColor in
                if trainCollection.userInterfaceStyle == .dark {
                    return UIColor.systemBackground
                }
                return UIColor.white
            }
            return _bc
        }
        return UIColor.white
    }()
    
    /** 更多图片 */
    static let K_APP_MORE_IMAGE:YYImage = {
        if #available(iOS 13.0, *) {
            if UIApplication.shared.keyWindow?.rootViewController!.traitCollection.userInterfaceStyle == .dark {
                return YYImage.init(named: "nav_more_white.png")!
            }
            return YYImage.init(named: "nav_more.png")!
        }
        return YYImage.init(named: "nav_more.png")!
    }()
    
    /** 新建视图背景色 */
    static let K_APP_CREATE_VIEW_BG:UIColor = {
        if #available(iOS 13, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.systemBackground
                }
                return UIColor.init(hexString: "#F0F1F4")!
            }
            return _c
        }
        return UIColor.init(hexString: "#F0F1F4")!
    }()
    
    /** 系统视图宽度 */
    static let K_APP_WIDTH = UIScreen.main.bounds.size.width
    
    /** 系统视图高度 */
    static let K_APP_HEIGHT = UIScreen.main.bounds.size.height
    
    /** 比率(宽) */
    static let K_APP_PROPORTION:CGFloat = UIScreen.main.bounds.size.width / 375.0
    /** 比率(高) */
    static let K_APP_VERTICAL_PROPORTION:CGFloat = UIScreen.main.bounds.size.height / 667.0
    
    /** iPhoneX底部区域 */
    static let K_APP_IPHONX_BUTTOM = CGFloat.init(34)
    
    /** iPhoneX顶部 导航 区域 */
    static let K_APP_IPHONX_TOP = CGFloat.init(44)
    
    /** 底部tabbar 高度 */
    static let K_APP_TABBAR_HEIGHT = CGFloat.init(UIDevice.current.isiPhoneX() ? 82.0 : 48.0)
    
    /** 安全区域 */
    static let K_APP_SAFETY_HEIGHT = UIDevice.current.isiPhoneX() ? K_APP_IPHONX_BUTTOM : 0.0
    static let K_APP_SAFETY_NAV_HEIGHT = UIDevice.current.isiPhoneX() ? K_APP_IPHONX_TOP : 20.0
    
    ////////////////////////////////////////////////////////////////////////////////
    
    //网络连接通知键
    static let K_APP_IS_NET_WORK = "app_is_net_work_notice_key"
    static let K_APP_IS_NET_WORK_CODE = "app_is_net_work_code_key"
    
    //app 引导 key
    static let K_APP_START_GUIDE_VIEW_KEY = "app_start_guide_view"
    static let K_APP_START_GUIDE_VIEW_HAS_KEY = "app_start_guide_view_has"
    
    /** tbbbar顶部线 */
    static let K_APP_TABBAR_TOP_LINE = "app_tabbar_top_line"
    
    /** 透明图片 */
    static let K_APP_TABBAR_CLEARN_IMAGE = "app_tabbar_clearn_image"
    
    /** 默认占位小图 */
    static let K_APP_DEFAULT_IMAGE_SMALL = "main_none_img_small"
    
    /** 默认占位大图 */
    static let K_APP_DEFAULT_IMAGE_BIG = "main_none_img_big"
    
    /** 默认背景色 */
    static let K_APP_DEFAULT_BG_COLOR = UIColor.init().colorFromHexInt(hex: 0xF0F0F0)
    
    /** 默认用户图像 */
    static let K_APP_DEFAULT_USER_IMAGE = "defaultAvatar"
    
    /** 图片上传指定的类型 */
    static let K_UPLOAD_IMAGE_TYPE_SET = "image/jpge,image/gif,image/jpeg,image/png,image/pjpeg"
    
    /** 轮播间隔时间（单位：秒）*/
    static let K_APP_AUTO_SCROLL_INTERVAL:CGFloat = 3
    
    /** 弹框 */
    static let K_APP_SHOW_BOX = "app_show_wechar"
    
    /** 启动图沉睡总时间(单位：秒) */
    static let K_STARTUP_TIME:TimeInterval = 3
    
    ////////////////////////////////////////////////////////////////////////////////
    //MARK: - UI字体、颜色配置信息
    ////////////////////////////////////////////////////////////////////////////////
    /** App主颜色 */
    static let K_APP_TINT_COLOR = UIColor.init().colorFromHexInt(hex: 0x2C4B63)
    
    /** 视图标题颜色 */
    static let K_APP_VIEWCONTROLLER_TITLE_COLOR = UIColor.init().colorFromHexString(hex: "#333333")
    
    /** 视图标题大小 */
    static let K_APP_VIEWCONTROLLER_TITLE_FONT = CGFloat.init(18)
    
    /** 列内容视图背景色、兼容夜间模式 */
    static let K_APP_CELL_BGCOLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.init().colorFromHexInt(hex: 0x2D2D2D,alpha: 0.6)
                }
                return UIColor.white
            }
            return _c
        }
        return UIColor.white
    }()
    
    /** 列选中背景色 */
    static let K_APP_CELL_SELECT_BGCOLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.init(hexString: "#2D2D2D")!
                }
                return UIColor.init(hexString: "#eff3ff")!
            }
            return _c
        }
        else{
            return UIColor.init(hexString: "#eff3ff")!
        }
    }()
    
    /** 分割线颜色 */
    static let K_APP_SPLIT_LINE_COLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.lightGray
                }
                return UIColor.init().colorFromHexInt(hex: 0xE9E9E9)
            }
            return _c
        }
        return UIColor.init().colorFromHexInt(hex: 0xE9E9E9)
    }()
    
    /** 分隔条颜色 */
    static let K_APP_SPLIT_STRIP_COLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.init().colorFromHexInt(hex: 0x2D2D2D)
                }
                return UIColor.init().colorFromHexInt(hex: 0xF8F8F8)
            }
            return _c
        }
        return UIColor.init().colorFromHexInt(hex: 0xF8F8F8)
    }()
    
    /** boxView 标题颜色 */
    static let K_APP_BOXVIEW_TITLE_COLOR:UIColor = {
        if #available(iOS 13.0, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.white
                }
                return UIColor.black
            }
            return _c
        }
        return UIColor.black
    }()
    
    //标题颜色
    static let K_APP_CELL_TITLE_COLOR:UIColor = {
        if #available(iOS 13, *) {
            let _c = UIColor.init { (traitCollection:UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return UIColor.init().colorFromHexInt(hex: 0xB5B3B3)
                }
                return UIColor.init().colorFromHexInt(hex: 0x333333)
            }
            return _c
        }
        return UIColor.init().colorFromHexInt(hex: 0x333333)
    }()
    
    /** 视图阴影颜色 */
    static let K_APP_VIEW_SHADOW_COLOR = UIColor.init().colorFromHexInt(hex: 0x000000,alpha: 0.09)
    
    /** 未启用视图颜色 */
    static let K_APP_VIEW_UNABLE_COLOR = UIColor.init().colorFromHexInt(hex: 0xc5c5c5)
    
    /** 视图阴影透明度 */
    static let K_APP_VIEW_CELL_SHADOW_OPACITY = Float.init(0.3)
    
    /** 发送验证码倒计时(单位:s) */
    static let K_APP_COUNT_DOWN = 60
    
    /** 验证码长度 */
    static let K_APP_CODE_LENGTH = 4
    
    /** 视频清晰度 */
    static let K_APP_VIDEO_DEFINITION = ["流畅","标清","高清","超清"]
    
    ////////////////////////////////////////////////////////////////////////////////
    //MARK: - 友盟配置
    ////////////////////////////////////////////////////////////////////////////////
    static let K_APP_UMENG_APP_KEY: String = "5fcf1ba8bed37e4506c5bcec"
    
    //QQ、Qzone、TIM
    static let K_APP_QQ_APP_ID = "101935206"
    static let K_APP_QQ_APP_KEY = "67309cc4d27515abeceee8f4cdc16696"
    static let K_APP_QQ_UNIVERSAL_LINK = "https://app.shlingzhang.com/qq_conn/101935206"
    
    //新浪微博
    static let K_APP_SINA_APP_KEY = "4015625823"
    static let K_APP_SINA_APP_SECRET = "2a26cac99d7a588c660e26e884e4a6b9"
    
    //微信
    static let K_APP_WECHART_APP_ID = "wx096ab426e89a60a0"
    static let K_APP_WECHART_APP_SECRET = "b1575d3ed3d2c296200a87636f2a7898"
    static let K_APP_UNIVERSAL_LINK = "https://app.shlingzhang.com/app/"
    
    
    ////////////////////////////////////////////////////////////////////////////////
    //MARK: - 极光推送
    ////////////////////////////////////////////////////////////////////////////////
    static let K_APP_JPUSH_KEY = UrlSetting.K_APP_IS_PRODUCT ? "5e3878e96ef7c50af540b342":"72b130bae8ed22aea367b6e3"
    
    static let K_APP_JPUSH_CHANNEL = "App Store"
    
    /** 资讯推送Tag */
    static let K_APP_JPUSH_NEWS_TAG:Set<String> = ["NEWS"]
    
    
    ////////////////////////////////////////////////////////////////////////////////
    //MARK: - 头部菜单配置信息
    ////////////////////////////////////////////////////////////////////////////////
    //头部选中菜单颜色、默认颜色
    static let K_HEAD_MENU_SELECT_COLOR = UIColor.init().colorFromHexInt(hex: 0x2C4B63)
    static let K_HEAD_MENU_DEFAULT_COLOR = UIColor.init().colorFromHexInt(hex: 0x2C4B63,alpha: 0.59)
    static let K_HEAD_MENU_BOTTOM_LINE_COLOR = UIColor.init().colorFromHexInt(hex: 0xF7F7FA)
    
    //头部菜单字体
    static let K_HEAD_MENU_FONT:UIFont = UIFont.systemFont(ofSize: 16, weight: .bold)
    static let K_HEAD_MENU_SELECT_FONT:UIFont = UIFont.systemFont(ofSize: 18, weight: .bold)
    
    //头部菜单字体
    static let K_HEAD_MENU_FONT_SIZE = CGFloat.init(16)
    
    //选中菜单字体
    static let K_HEAD_MENU_SELECT_FONT_SIZE = CGFloat.init(18)
    
    //缩放级别
    static let K_HEAD_MENU_SCALE = CGFloat.init(1.06)
    
    //菜单底部指示线宽度
    static let K_HEAD_BOTTOM_LINE_WIDTH = CGFloat.init(15)
    
    //菜单底部指示线高度
    static let K_HEAD_BOTTOM_LINE_HEIGHT = CGFloat.init(2)
    
    //菜单底部指示线颜色
    static let K_HEAD_BOTTOM_LINE_COLOR = UIColor.init().colorFromHexInt(hex: 0xF12525)
    
    /** 资讯类别键 */
    static let K_INFORMATION_COLUMN = "news_category_key"
    
    /** 首页已启用菜单 */
    static let K_HOME_IN_USE_MENUS = "home_in_use_menus"
    
    /** 系统信息 */
    static let K_SYSINFO_KEY = "app_sys_info"
    
    //MARK: - 刷新、加载更多
    static let K_APP_LOADING_INFO = "加载中..."
    
    /** MJRefreshGifHeader */
    static func K_APP_REFRESH_HEADER(refreshBlock:@escaping(()->Void)) -> MJRefreshGifHeader {
        
        let gifH:MJRefreshGifHeader = MJRefreshGifHeader.init()
        
        //隐藏文本
        gifH.stateLabel?.isHidden = true
        
        //刷新回调
        gifH.refreshingBlock = refreshBlock
        
        //下拉中
        gifH.setImages([ YYImage.init(named: "gomro20000.png") as Any,
                         YYImage.init(named: "gomro20001.png") as Any,
                         YYImage.init(named: "gomro20002.png") as Any,
                         YYImage.init(named: "gomro20003.png") as Any,
                         YYImage.init(named: "gomro20004.png") as Any,
                         YYImage.init(named: "gomro20005.png") as Any,
                         YYImage.init(named: "gomro20006.png") as Any,
                         YYImage.init(named: "gomro20007.png") as Any,
                         YYImage.init(named: "gomro20008.png") as Any,
                         YYImage.init(named: "gomro20009.png") as Any,
                         YYImage.init(named: "gomro20010.png") as Any,
                         YYImage.init(named: "gomro20011.png") as Any,
                         YYImage.init(named: "gomro20012.png") as Any], for: .pulling)
        
        //即将刷新
        gifH.setImages([ YYImage.init(named: "gomro20000.png") as Any,
                         YYImage.init(named: "gomro20001.png") as Any,
                         YYImage.init(named: "gomro20002.png") as Any,
                         YYImage.init(named: "gomro20003.png") as Any,
                         YYImage.init(named: "gomro20004.png") as Any,
                         YYImage.init(named: "gomro20005.png") as Any,
                         YYImage.init(named: "gomro20006.png") as Any,
                         YYImage.init(named: "gomro20007.png") as Any,
                         YYImage.init(named: "gomro20008.png") as Any,
                         YYImage.init(named: "gomro20009.png") as Any,
                         YYImage.init(named: "gomro20010.png") as Any,
                         YYImage.init(named: "gomro20011.png") as Any,
                         YYImage.init(named: "gomro20012.png") as Any], for: .willRefresh)
        
        //刷新中
        gifH.setImages([ YYImage.init(named: "gomro20000.png") as Any,
                         YYImage.init(named: "gomro20001.png") as Any,
                         YYImage.init(named: "gomro20002.png") as Any,
                         YYImage.init(named: "gomro20003.png") as Any,
                         YYImage.init(named: "gomro20004.png") as Any,
                         YYImage.init(named: "gomro20005.png") as Any,
                         YYImage.init(named: "gomro20006.png") as Any,
                         YYImage.init(named: "gomro20007.png") as Any,
                         YYImage.init(named: "gomro20008.png") as Any,
                         YYImage.init(named: "gomro20009.png") as Any,
                         YYImage.init(named: "gomro20010.png") as Any,
                         YYImage.init(named: "gomro20011.png") as Any,
                         YYImage.init(named: "gomro20012.png") as Any,
                         YYImage.init(named: "gomro20013.png") as Any,
                         YYImage.init(named: "gomro20014.png") as Any,
                         YYImage.init(named: "gomro20015.png") as Any,
                         YYImage.init(named: "gomro20016.png") as Any,
                         YYImage.init(named: "gomro20017.png") as Any,
                         YYImage.init(named: "gomro20018.png") as Any,
                         YYImage.init(named: "gomro20019.png") as Any,
                         YYImage.init(named: "gomro20020.png") as Any,
                         YYImage.init(named: "gomro20021.png") as Any,
                         YYImage.init(named: "gomro20022.png") as Any,
                         YYImage.init(named: "gomro20023.png") as Any,
                         YYImage.init(named: "gomro20024.png") as Any,
                         YYImage.init(named: "gomro20025.png") as Any,
                         YYImage.init(named: "gomro20026.png") as Any,
                         YYImage.init(named: "gomro20027.png") as Any,
                         YYImage.init(named: "gomro20028.png") as Any,
                         YYImage.init(named: "gomro20029.png") as Any,
                         YYImage.init(named: "gomro20030.png") as Any,
                         YYImage.init(named: "gomro20031.png") as Any,
                         YYImage.init(named: "gomro20032.png") as Any], for: .refreshing)
        
        //图片居中
        gifH.gifView?.snp.makeConstraints {make in
            let _window:UIWindow = (UIApplication.shared.keyWindow ?? UIApplication.shared.windows.first)!
            make.centerX.equalTo(_window.centerX)
        }
        
        return gifH
    }
    
    /** MJRefreshBackGifFooter */
    static func K_APP_REFRESH_FOOTER(refreshBlock:@escaping(()->Void)) -> MJRefreshBackGifFooter {
        
        let gifH:MJRefreshBackGifFooter = MJRefreshBackGifFooter.init()
        
        //隐藏文本
        //gifH.stateLabel.isHidden = true
        
        //刷新回调
        gifH.refreshingBlock = refreshBlock
        
        //下拉中
        gifH.setImages([ YYImage.init(named: "gomro20000.png") as Any,
                         YYImage.init(named: "gomro20001.png") as Any,
                         YYImage.init(named: "gomro20002.png") as Any,
                         YYImage.init(named: "gomro20003.png") as Any,
                         YYImage.init(named: "gomro20004.png") as Any,
                         YYImage.init(named: "gomro20005.png") as Any,
                         YYImage.init(named: "gomro20006.png") as Any,
                         YYImage.init(named: "gomro20007.png") as Any,
                         YYImage.init(named: "gomro20008.png") as Any,
                         YYImage.init(named: "gomro20009.png") as Any,
                         YYImage.init(named: "gomro20010.png") as Any,
                         YYImage.init(named: "gomro20011.png") as Any,
                         YYImage.init(named: "gomro20012.png") as Any], for: .pulling)
        
        //刷新中
        gifH.setImages([ YYImage.init(named: "gomro20000.png") as Any,
                         YYImage.init(named: "gomro20001.png") as Any,
                         YYImage.init(named: "gomro20002.png") as Any,
                         YYImage.init(named: "gomro20003.png") as Any,
                         YYImage.init(named: "gomro20004.png") as Any,
                         YYImage.init(named: "gomro20005.png") as Any,
                         YYImage.init(named: "gomro20006.png") as Any,
                         YYImage.init(named: "gomro20007.png") as Any,
                         YYImage.init(named: "gomro20008.png") as Any,
                         YYImage.init(named: "gomro20009.png") as Any,
                         YYImage.init(named: "gomro20010.png") as Any,
                         YYImage.init(named: "gomro20011.png") as Any,
                         YYImage.init(named: "gomro20012.png") as Any,
                         YYImage.init(named: "gomro20013.png") as Any,
                         YYImage.init(named: "gomro20014.png") as Any,
                         YYImage.init(named: "gomro20015.png") as Any,
                         YYImage.init(named: "gomro20016.png") as Any,
                         YYImage.init(named: "gomro20017.png") as Any,
                         YYImage.init(named: "gomro20018.png") as Any,
                         YYImage.init(named: "gomro20019.png") as Any,
                         YYImage.init(named: "gomro20020.png") as Any,
                         YYImage.init(named: "gomro20021.png") as Any,
                         YYImage.init(named: "gomro20022.png") as Any,
                         YYImage.init(named: "gomro20023.png") as Any,
                         YYImage.init(named: "gomro20024.png") as Any,
                         YYImage.init(named: "gomro20025.png") as Any,
                         YYImage.init(named: "gomro20026.png") as Any,
                         YYImage.init(named: "gomro20027.png") as Any,
                         YYImage.init(named: "gomro20028.png") as Any,
                         YYImage.init(named: "gomro20029.png") as Any,
                         YYImage.init(named: "gomro20030.png") as Any,
                         YYImage.init(named: "gomro20031.png") as Any,
                         YYImage.init(named: "gomro20032.png") as Any], for: .refreshing)
        
        //图片居中
        gifH.gifView?.snp.makeConstraints {make in
            let _window:UIWindow = (UIApplication.shared.keyWindow ?? UIApplication.shared.windows.first)!
            make.centerX.equalTo(_window.centerX)
        }
        
        gifH.stateLabel?.snp.makeConstraints {make in
            let _window:UIWindow = (UIApplication.shared.keyWindow ?? UIApplication.shared.windows.first)!
            make.top.equalTo(gifH.gifView!.snp.bottom)
            make.centerX.equalTo(_window.centerX)
        }
        
        return gifH
    }
    
}

